package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RxDoudianGoods;
import com.ruoyi.system.service.IRxDoudianGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 抖店商品管理Controller
 *
 * @author hjf
 * @date 2025-05-20
 */
@RestController
@RequestMapping("/hmk/douDianGoods")
public class RxDoudianGoodsController extends BaseController {
    @Autowired
    private IRxDoudianGoodsService rxDoudianGoodsService;

    /**
     * 查询抖店商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:douDianGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(RxDoudianGoods rxDoudianGoods) {
        startPage();
        List<RxDoudianGoods> list = rxDoudianGoodsService.selectRxDoudianGoodsList(rxDoudianGoods);
        return getDataTable(list);
    }

    /**
     * 导出抖店商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:douDianGoods:export')")
    //@Log(title = "抖店商品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RxDoudianGoods rxDoudianGoods) {
        List<RxDoudianGoods> list = rxDoudianGoodsService.selectRxDoudianGoodsList(rxDoudianGoods);
        ExcelUtil<RxDoudianGoods> util = new ExcelUtil<RxDoudianGoods>(RxDoudianGoods.class);
        util.exportExcel(response, list, "抖店商品管理数据");
    }

    /**
     * 获取抖店商品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('hmk:douDianGoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rxDoudianGoodsService.selectRxDoudianGoodsById(id));
    }

    /**
     * 新增抖店商品管理
     */
    @PreAuthorize("@ss.hasPermi('hmk:douDianGoods:add')")
    //@Log(title = "抖店商品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RxDoudianGoods rxDoudianGoods) {
        rxDoudianGoods.setTime(System.currentTimeMillis() / 1000);
        return toAjax(rxDoudianGoodsService.insertRxDoudianGoods(rxDoudianGoods));
    }

    /**
     * 修改抖店商品管理
     */
    @PreAuthorize("@ss.hasPermi('hmk:douDianGoods:edit')")
    //@Log(title = "抖店商品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RxDoudianGoods rxDoudianGoods) {
        return toAjax(rxDoudianGoodsService.updateRxDoudianGoods(rxDoudianGoods));
    }

    /**
     * 删除抖店商品管理
     */
    @PreAuthorize("@ss.hasPermi('hmk:douDianGoods:remove')")
    //@Log(title = "抖店商品管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rxDoudianGoodsService.deleteRxDoudianGoodsByIds(ids));
    }
}
